<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <span>{{ company.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row
        type="flex"
        justify="space-between"
        align="middle"
        style="height: 40px"
      >
        <el-col>
          <span style="margin-right:5px">{{ company.manager }}</span>
        </el-col>
        <el-col>
          <el-dropdown class="avatar-container">
            <div class="avatar-wrapper">
              <span>操作</span>
              <i class="el-icon-arrow-down" />
            </div>
            <el-dropdown-menu slot="dropdown" class="user-dropdown">
              <el-dropdown-item>
                <el-button
                  :disabled="isCheck('aa')"
                  @click="addDeps"
                >添加子部门=={{ isCheck('aa') }}</el-button>
              </el-dropdown-item>
              <el-dropdown-item v-if="isLevel">
                <span @click="editDept">编辑部门</span>
              </el-dropdown-item>
              <el-dropdown-item
                v-if="isLevel"
              ><span @click="delDept">删除部门</span></el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments'
export default {
  name: '',
  props: {
    company: {
      type: Object
    },
    isLevel: {
      type: Boolean,
      default: false
    }
  },
  created() {
    // this.isCheck()
  },
  methods: {
    addDeps() {
      console.log(2222222)
      //  添加部门
      /*
      1-显示对话框
      2-获取部门负责人数据
      3-表单校验
      4-点击确认按钮
        4-1 二次校验
        4-2 获取数据表单数据
        4-3 发送添加部门的请求
        4-4 关闭对话框
        4-5 更新数据
      */
      this.$emit('addDeps', this.company, 'add')
    },

    /* 编辑 */
    editDept() {
      this.$emit('addDeps', this.company, 'edit')
    },
    /* 删除 */
    delDept() {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {
          await delDepartments(this.company.id)
          this.$emit('close') // 在触发父组件中的数据  刷新页面
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
<style lang="less" scoped></style>
